var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
    value: !0
});
var o = e("DataMgr"),
i = e("VideoHint"),
a = e("OpenBoxMgr"),
r = cc._decorator,
s = r.ccclass,
c = r.property,
l = function(e) {
    __extends(t, e);
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        t.stateNodes = [];
        t.priceLabel = null;
        t.boxSprite = null;
        t.spriteFrames = [];
        t.rewardNum = 100;
        t.hasOpen = !1;
        t.isAdBox = !1;
        return t
    }
    t.prototype.reset = function() {
        this.hasOpen = !1;
        this.stateNodes[0].active = !0;
        this.stateNodes[1].active = !1;
        this.AdBox(!1)
    };
    t.prototype.setReward = function(e) {
        this.rewardNum = e;
        this.priceLabel.string = this.rewardNum.toString();
        this.boxSprite.spriteFrame = this.spriteFrames[0]
    };
    t.prototype.AdBox = function(e) {
        void 0 === e && (e = !0);
        this.isAdBox = e;
        this.isAdBox ? this.stateNodes[0].getComponent(cc.Sprite).spriteFrame = a.default.Instance.adBoxSprite: this.stateNodes[0].getComponent(cc.Sprite).spriteFrame = a.default.Instance.noAdBoxSprite
    };
    t.prototype.open = function() {
        if (this.hasOpen) SDK.ToastMgr.Inst.showToast("宝箱已打开");
        else if (this.isAdBox) {
            var e = "OpenBox_SingleOpen_Ad";
            SDK.Mgr.Inst.event(e + "Click");
            var t = this,
            n = function(a) {
                if (a == SDK.Define.AdsCode.finish) {
                    SDK.Mgr.Inst.event(e + "Success");
                    t.openReal(!1);
                    o.default.Instance.videoAdTimes++
                } else if (a == SDK.Define.AdsCode.cancel) {
                    SDK.Mgr.Inst.event(e + "Cancel");
                    i.default.Instance.openPanel(n)
                } else {
                    SDK.ToastMgr.Inst.showToast("暂无广告，请稍后再试");
                    SDK.Mgr.Inst.event(e + "NoAd")
                }
            };
            SDK.Mgr.Inst.showVideo(n)
        } else a.default.Instance.restTime <= 0 ? SDK.ToastMgr.Inst.showToast("开箱次数已用完") : this.openReal()
    };
    t.prototype.openReal = function(e) {
        var t = this;
        void 0 === e && (e = !0);
        a.default.Instance.openBox(e);
        this.hasOpen = !0;
        this.scheduleOnce(function() {
            t.stateNodes[0].active = !1;
            t.stateNodes[1].active = !0;
            o.default.Instance.coinNum += t.rewardNum
        },
        .1)
    };
    __decorate([c([cc.Node])], t.prototype, "stateNodes", void 0);
    __decorate([c(cc.Label)], t.prototype, "priceLabel", void 0);
    __decorate([c(cc.Sprite)], t.prototype, "boxSprite", void 0);
    __decorate([c([cc.SpriteFrame])], t.prototype, "spriteFrames", void 0);
    return __decorate([s], t)
} (cc.Component);
n.default = l